using System.Collections.Generic;
using UnityEngine;

public class LevelUI : MonoBehaviour
{
	private GameObject uiobj;

	public List<biglevel> biglevels;

	public List<level_item_ui> levelitems;

	public Transform root;

	public bool runflag;

	public UIEventListener lastbtn;

	public UIEventListener nextbtn;

	public UIWidget lastwi;

	public UIWidget nextwi;

	public TweenPosition[] animaPos;

	private Vector3 leftpos = new Vector3(-1000f, 0f, 0f);

	private Vector3 rightpos = new Vector3(1000f, 0f, 0f);

	private int curbiglevelnum;

	private bool scrollmoveflag;

	private int startindex;

	private int endindex;

	private float temptime;

	private float timerange = 1.1f;

	private void Start()
	{
		lastbtn.onClick = onclicklastbtn;
		nextbtn.onClick = onclicknextbtn;
	}

	public void init_ui_info()
	{
		for (int i = 0; i < biglevels.Count; i++)
		{
			animaPos[i].enabled = false;
			if (i == curbiglevelnum)
			{
				biglevels[i].enable();
				animaPos[i].transform.localPosition = Vector3.zero;
			}
			else
			{
				biglevels[i].disable();
			}
		}
		show_info();
	}

	public void show_info()
	{
		if (curbiglevelnum < 0)
		{
			return;
		}
		MenuPlayerprefs.instance.readAllLevel();
		int num = MenuPlayerprefs.instance.biglevelinfo[curbiglevelnum];
		int curgamelevel = MenuPlayerprefs.instance.curgamelevel;
		num %= 1000000;
		for (int i = curbiglevelnum * 6; i < curbiglevelnum * 6 + 6; i++)
		{
			levelitems[i].showUI(num % 10, curgamelevel);
			num /= 10;
		}
		if (curbiglevelnum >= 1)
		{
			lastwi.alpha = 1f; lastwi.gameObject.SetActive(true);
		}
		else
		{
			lastwi.alpha = 0f; lastwi.gameObject.SetActive(false);
		}
		if (curbiglevelnum + 1 <= 7)
		{
			if (MenuPlayerprefs.instance.biglevelinfo[curbiglevelnum + 1] / 1000000 == 1)
			{
				nextwi.alpha = 1f; nextwi.gameObject.SetActive(true);
			}
			else
			{
				nextwi.alpha = 0f; nextwi.gameObject.SetActive(false);
			}
		}
		else
		{
			nextwi.alpha = 0f; nextwi.gameObject.SetActive(false);
		}
	}

	public void onclicklastbtn(GameObject btn)
	{
		if (curbiglevelnum > 0 && !scrollmoveflag)
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN1, 0f);
			scrollmoveflag = true;
			startindex = curbiglevelnum;
			endindex = curbiglevelnum - 1;
			animaPos[startindex].from = Vector3.zero;
			animaPos[startindex].to = rightpos;
			animaPos[startindex].duration = timerange - 0.1f;
			animaPos[startindex].ResetToBeginning();
			animaPos[endindex].from = leftpos;
			animaPos[endindex].to = Vector3.zero;
			animaPos[endindex].duration = timerange - 0.1f;
			animaPos[endindex].ResetToBeginning();
			biglevels[endindex].enable();
			curbiglevelnum--;
			show_info();
			animaPos[startindex].PlayForward();
			animaPos[endindex].PlayForward();
			temptime = 0f;
		}
	}

	public void onclicknextbtn(GameObject btn)
	{
		if (curbiglevelnum < 7 && !scrollmoveflag)
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN1, 0f);
			scrollmoveflag = true;
			startindex = curbiglevelnum;
			endindex = curbiglevelnum + 1;
			animaPos[startindex].from = Vector3.zero;
			animaPos[startindex].to = leftpos;
			animaPos[startindex].duration = timerange - 0.1f;
			animaPos[startindex].ResetToBeginning();
			animaPos[endindex].from = rightpos;
			animaPos[endindex].to = Vector3.zero;
			animaPos[endindex].duration = timerange - 0.1f;
			animaPos[endindex].ResetToBeginning();
			biglevels[endindex].enable();
			curbiglevelnum++;
			show_info();
			animaPos[startindex].PlayForward();
			animaPos[endindex].PlayForward();
			temptime = 0f;
		}
	}

	private void Update()
	{
		if (scrollmoveflag)
		{
			temptime += Time.deltaTime;
			if (temptime >= timerange)
			{
				scrollmoveflag = false;
				temptime = 0f;
				biglevels[startindex].disable();
				animaPos[endindex].transform.localPosition = Vector3.zero;
			}
		}
	}

	public void enable(int level_index)
	{
		if (uiobj == null)
		{
			uiobj = base.gameObject;
		}
		NGUITools.SetActive(uiobj, state: true);
		curbiglevelnum = level_index;
		init_ui_info();
		scrollmoveflag = false;
	}

	public void disable()
	{
		NGUITools.SetActive(uiobj, state: false);
	}
}
